package com.weipai.demo.controller;

import com.weipai.demo.util.JPushUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 *
 */
public class BaseController {




	//=========消息推送================
	public void pushMsg(Map<String, String> map){
		JPushUtil.jpushAndroid(map);
		JPushUtil.jpushIOS(map);
	}


	/**
	 * 获取普通用户的登录信息
	 * @param session
	 * @return
	 */
/*	public Map<String,String> getComnUserData(HttpSession session ){
		return SessionUserUtil.getUserAttr(session);
	}*/
	/**
	 * 判断当前session是否有普通用户登录
	 * @param session
	 * @return
	 */
	/*public boolean isComnUserLogin(HttpSession session ){
		return SessionUserUtil.getUserAttr(session)!=null ;
	}*/
	/**
	 * 创建图片下载地址
	 * @param request
	 * @param url
	 * @return
	 */
	public String createDownLoadUrl(HttpServletRequest request, String url){
		return request.getContextPath()+url ;
	}
	/**
	 * 获取基础路径
	 * @author duxiaozheng
	 * @date 2016年11月24日下午7:05:24
	 * @MethodName contextPath
	 * @param 
	 */
	public String contextPath(HttpServletRequest request){
		return request.getContextPath();
	}	
	/**
	 * 获取登陆人信息中的角色
	 * @param user
	 * @return
	 */
	public String getCurrentUserRole(Map<String,String> user){
		return user.get("role");
	}
	/**
	 * 判断登陆人是否为后台超级管理员
	 * @param user
	 * @return
	 */
/*	public boolean isSellerSuperAdmin(Map<String,String> user){
		String role = getCurrentUserRole(user);
		return (""+RoleType.SELLER_ADMIN_SUPER).equals(role);
	}*/
	/**
	 * 判断登陆人是否为普通管理员
	 * @param user
	 * @return
	 */
/*	public boolean isSellerNormalAdmin(Map<String,String> user){
		String role = getCurrentUserRole(user);
		return (""+RoleType.SELLER_ADMIN_NORMAL).equals(role);
	}*/
	
	/**
	 * 判断登陆人是否具备超级管理的权限
	 * @param user
	 * @return
	 */
	/*public boolean isSellerAdmin(Map<String,String> user){
		return isSellerNormalAdmin(user) || isSellerSuperAdmin(user);
	}*/
	
	
	/**
	 * 获取登陆人信息中的所属服务商或者上级的id
	 * @param user
	 * @return
	 */
	public String getCurrentUserUnitsid(Map<String,String> user){
		return user.get("unitsid");
	}
	
	/*public void writeJson(HttpServletResponse response, Object object) throws IOException{
	 	response.setCharacterEncoding("utf-8");
	    response.getWriter().print(JSONUtils.toJSON(object));
	}*/
	
	/*public String getAliPrivateKey(){
		return AliPayUtil.APP_PRIVATE_KEY;
	}
	
	public String getAliPublicKey(){
		return AliPayUtil.APP_PUBLIC_KEY;
	}
	
	public String getAliPayPublicKey(){
		return AliPayUtil.ALIPAY_PUBLIC_KEY;
	}
	*/
	/**
	 * 验证银行卡号  银行卡和用户名验证
	 * @param cardNum
	 * @param name
	 * @return
	 */
	/*public boolean getCardAuthentication(String cardNum, String name){
		return AuthenticationUtil.getRequest1(cardNum, name);
	}*/
	
	/**
	 * 取得开户行
	 * @param cardNum
	 * @return
	 */
	/*public String getBankName(String cardNum){
		return BankCardUtil.getname(cardNum);
	}*/
	
	/**
	 * 实名认证
	 * @param cardNum
	 * @param name
	 * @return
	 */
	/*public boolean getNameAuthentication(String cardNum, String name){
		return AuthenticationUtil.getRequest2(cardNum, name);
	}
	
	public String sendCode(String phone, String code, String type){
		return SendCodeUtil.sendvercode(phone, code, type);
	}
	
	public Map<String, String> toPay(HttpServletRequest request, HttpServletResponse response, String orderNum, Recharge order){

		return WechatpayUtil.toPay(request, response, orderNum, order);
	}*/
	

	public void pushAndroidMsg(Map<String, String> map){
		JPushUtil.jpushAndroid(map);
	}
	
	/*public void pushIOSMsg(Map<String, String> map){
		JPushUtil.jpushIOS(map);
	}
	
	public String creatAliPaySign(AlipayTradeAppPayModel model){
		return AliPayUtil.creatSign(model);
	}
	
	//云信注册用户,返回token
	public String getIMToken(String accid, String name){
		return NetEaseIMUtil.neteaseClient(accid, name);
	}
	//云信创建群组
	public String creatGroup(String tname, String owner, String members,  String msg, int magree, int joinmode, String icon ){
		return NetEaseIMUtil.creatGroup(tname, owner, members, msg, magree, joinmode, icon);
	}

	//云信创建群组-------------------------------------------8-14新增
	public String creatGroup(String tname, String msg, int magree, int joinmode, String icon ){
		return NetEaseIMUtil.creatGroup(tname, msg, magree, joinmode, icon);
	}



	//云信群组邀请人员
	public String inviteUserToGroup(String tid, String owner, String members, int magree, String msg){
		return NetEaseIMUtil.inviteUserToGroup(tid, owner, members, magree, msg);
	}
	//群组移除人员
	public String kickGroup(String tid, String owner, String member){
		return NetEaseIMUtil.kickGroup(tid, owner, member);
	}
	
	public String getRandom(long l){
		return NetEaseIMUtil.creatNonce(l);
	}
	
	public String toJsonString(List<String> list){
		return DataConversionUtil.toJsonString(list);
	}
	
	public List<String> toList(String jsonString){
		return DataConversionUtil.toList(jsonString);
	}
	
	public Map<String, Object> toMap(String str){
		return DataConversionUtil.toMap(str);
	}

	public static Map<String, String> creatUser(User user){
		Map<String, String> map = new HashMap<String, String>();
		map.put("id", user.getId());
		map.put("headPic", user.getHeadPic());
		map.put("nickName", user.getNickName());
		map.put("userName", user.getUserName());
		map.put("mobile", user.getPhone());
		map.put("level", user.getUserLevel());
		return map;
	}*/
	
}
